# coding=utf-8

import json

import redis
from firefly.utils.singleton import Singleton


class RedisManager(object):
    __metaclass__ = Singleton

    def __init__(self):
        self.redis_client = None

        with open("config.json", 'r') as f:
            config = json.load(f)
            redis_cnf = config.get("redis", {})
        if redis_cnf:
            host = redis_cnf.get('host', "127.0.0.1")
            port = redis_cnf.get("port", 3639)
            redis_pass = redis_cnf.get("password", "")
            self.redis_client = redis.Redis(host=host, port=port, password=redis_pass, db=3)

    def get_client(self):
        return self.redis_client
